ROOTCONFIG   := root-config
ROOTCINT     := rootcint
ARCH         := $(shell $(ROOTCONFIG) --arch)
ROOTCFLAGS   := $(shell $(ROOTCONFIG) --cflags)
ROOTLDFLAGS  := $(shell $(ROOTCONFIG) --ldflags)
ROOTGLIBS    := $(shell $(ROOTCONFIG) --libs)

CXX           = g++
CXXFLAGS      = -O3 -Wall -fPIC
LD            = g++
LDFLAGS       = -O3
SOFLAGS       = -shared

CXXFLAGS     += $(ROOTCFLAGS)
LDFLAGS      += $(ROOTLDFLAGS) $(ROOTGLIBS)

CXXFLAGS     += -I$(MYSQL_INCLUDE)
LDFLAGS      += -lz -L$(MYSQL_LIB) -lmysqlclient

TRIGGERROADO  = TriggerRoad.o TriggerRoadDict.o
TRIGGERROADS  = TriggerRoad.cxx TriggerRoadDict.cxx

GEOMSVCO      = GeomSvc.o
GEOMSVCS      = GeomSvc.cxx

TRIGGERANAO   = TriggerAnalyzer.o
TRIGGERANAS   = TriggerAnalyzer.cxx

TRIGGERSO     = libTrigger.so

CLASSOBJS     = $(GEOMSVCO) $(TRIGGERROADO) $(TRIGGERANAO)
OBJS          = $(CLASSOBJS)
SLIBS         = $(TRIGGERSO)
PROGRAMS      = $(KSEEDER)

all:            $(PROGRAMS) $(SLIBS)

.SUFFIXES: .cxx .o

$(TRIGGERSO):  $(CLASSOBJS)
	$(LD) $(SOFLAGS) $(LDFLAGS) $^ -o $@
	@echo "$@ done."

.SUFFIXES: .cxx

TriggerRoadDict.cxx: TriggerRoad.h TriggerRoadLinkDef.h
	@echo "Generating dictionary for $@ ..."
	$(ROOTCINT) -f $@ -c $^

.cxx.o:
	$(CXX) $(CXXFLAGS) -c $<

.PHONY: clean

clean:
	@echo "Cleanning everything ... "
	@rm $(PROGRAMS) $(OBJS) $(SLIBS) *Dict.cxx *Dict.h
